var UserEditController = FormController.extend({
	_userModel : null,
	_location : null,
	_route : null,
	
	init : function($scope, userModel, $location, $route) {
		this._userModel = userModel;
		this._location = $location;
		this._route = $route;
		this._super($scope)
	},
	
	defineScope : function() {	
		var username = this._route.current.params.username;
		this._userModel.getById(username, function(data, status, headers, config) {
			this.$scope.user = data;
			this.$scope.originalemail = data['email'];
		}.bind(this));
		
		this.$scope.update = this.update.bind(this);
		this.$scope.deleteUser = this.deleteUser.bind(this);
	},
	
	update : function(user) {
		var convertdUser = {
				'username' : user.username,
				'fullname' : user.fullname,
				'email' : user.email,
				'roles' : [user.role],
				'enablement' : user.enablement
			}
			
		this._userModel.update(convertdUser, function(data, status, headers, config) {
			this._location.path('/system/user-management');
		}.bind(this));
	},
	
	deleteUser : function(username) {
		this._userModel.remove(username, function(data, status, headers, config) {
			this._location.path('/system/user-management');
		}.bind(this));
	}
})

UserEditController.$inject = ['$scope', 'UserModel', '$location', '$route'];